﻿using System;
using System.Collections;
using System.Data;
using CE.Database;

/// <summary>
/// Summary description for AreaInfoDB
/// </summary>
/// 

namespace CE.AreaCountry
{
    public class AreaInfoDB
    {
        public AreaInfoDB()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public Int64 Insert(AreaInfo areainfo)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "sprocAreaInfoInsertUpdateSingleItem";

            SortedList _sPara = new SortedList();

            #region Parameter

            _sPara.Add("@AreaID", areainfo.AreaId);
            _sPara.Add("@Description", areainfo.Description);
            _sPara.Add("@Status", areainfo.Status);

            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        public AreaInfo GetAreaInfo(Int64 ArId)
        {
            AreaInfo _areainfo = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocAreaInfoSelectItemList";

            SortedList _spara = new SortedList();
            _spara.Add("@AreaID", ArId);

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _spara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _areainfo = new AreaInfo();
                    _areainfo = FillDataRecord(_dt, 0);
                }
            }
            return _areainfo;
        }

        private AreaInfo FillDataRecord(DataTable myDataTable, int rowId)
        {
            AreaInfo myAreaInfo = new AreaInfo();
            myAreaInfo.AreaId = Convert.ToInt64(myDataTable.Rows[rowId]["AreaId"].ToString());
            myAreaInfo.Description = myDataTable.Rows[rowId]["Description"].ToString();
            myAreaInfo.Status = Convert.ToBoolean(myDataTable.Rows[rowId]["Status"].ToString());

            return myAreaInfo;
        }
    }
}
